package com.yangjie.user.domain;

import java.util.Collection;
import java.util.LinkedList;
import java.util.Set;

import org.springframework.security.core.userdetails.UserDetails;

public class UserDetailsAdapter implements UserDetails{
	User user = null;
	public UserDetailsAdapter(User user) {
		this.user = user;
	}
	@Override
	public Collection<PermissionAdapter> getAuthorities() {
		Collection<PermissionAdapter> retval = new LinkedList<PermissionAdapter>();
		for(Role role: user.getRoles()) {
			Set<Permission> permissionSet = role.getPermissions();
			for(Permission permission: permissionSet) {
				retval.add(new PermissionAdapter(permission));
			}
		}
		return retval;
	}

	@Override
	public String getPassword() {
		return user.getPassword();
	}

	@Override
	public String getUsername() {
		return user.getUsername();
	}

	@Override
	public boolean isAccountNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean isEnabled() {
		// TODO Auto-generated method stub
		return true;
	}
	
}
